unit Helper.Benchmark;

interface

uses
  SysUtils;

type
  TBenchmark = class
  private
    fFreq: Int64;
  public
    constructor Create;
    function Benchmark(aProc: TProc; aIterations, aWarmUp: integer): double;
  end;

implementation

uses
  Windows;

{ TBenchmark }

function TBenchmark.Benchmark(aProc: TProc; aIterations, aWarmUp: integer): double;
var
  start, stop: Int64;
  i: integer;
begin
  for i := 1 to aWarmUp do
  begin
    aProc;
  end;

  QueryPerformanceCounter(start);
  for i := 1 to aIterations do
  begin
    aProc;
  end;
  QueryPerformanceCounter(stop);

  result := (stop - start) / fFreq / aIterations;
end;

constructor TBenchmark.Create;
begin
  QueryPerformanceFrequency(fFreq);
end;

end.
